﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using NPMonitor.Implementation;
using NPMonitor.DataModel;

namespace NPMonitor.Web.UserControls
{
    public partial class HttpFrame : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (scenario != null)
                {
                    txtScenario.Text = scenario.ScenarioName;
                    txtUrl.Text = scenario.URL;
                }
                txtStartTime.Text = BeginTime;
                BindData(ActionId);
            }
        }

        public long ActionId
        {
            get
            {
                long actionId;
                long.TryParse(Request.QueryString["Actionid"], out actionId);
                return actionId;
            }
        }

        private Scenario scenario 
        {
            get
            {
                return StoreManager.Current.ReportStore.GetScenarioByActionId(ActionId);
            }
        }

        public string BeginTime
        {
            get
            {
                return Request.QueryString["begintime"];
            }
        }

        protected void BindData(long ActionId)
        {
            List<HttpActionRequestsData> dt = StoreManager.Current.ReportStore.GetHttpActionRequestsByActionId(ActionId);
            rptFrameTable.DataSource = dt;
            rptFrameTable.DataBind();
        }

        protected void rptFrameTable_ItemDataBound1(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item)
            {
                TimeChart item = e.Item.FindControl("utTimeChart") as TimeChart;
                HttpActionRequestsData data = e.Item.DataItem as HttpActionRequestsData;
                item.Blocked = data.Blocked;
                item.Wait = data.Wait;
                item.Send = data.Send;
                item.Receive = data.Receive;
                item.CacheRead = data.CacheRead;
                item.Network = data.Network;
            }
        }

    }
}